package edu.njfu.sas.servlet;

import com.google.gson.Gson;
import edu.njfu.sas.dao.impl.StudentDaoImpl3;
import edu.njfu.sas.model.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;

@WebServlet( "/GetStudentByName")
public class GetStudentByNameServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        String stuName=request.getParameter("stuName");
        stuName=stuName;
        System.out.println(stuName);
        StudentDaoImpl3 studentDao=new StudentDaoImpl3();
        //防止有同名得同学
        List<Student> result=studentDao.getStudentByName(stuName);
        PrintWriter out=response.getWriter();
        out.write(new Gson().toJson(result));


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
